<html>
<script>
	//回调地狱  --  深层次嵌套问题
	load("./data/1.json",function(data){
		document.write(data);
		
	});
	load("./data/2.json",function(data){
		document.write(data);
		
	});
	
	load("./data/3.json",function(data){
		document.write(data);
	});
	/*
	//yeild表示返回，然后函数会进入一个假死状态，直到下一次调用next复活
	function* fn(){
		let i = 0;
		console.log("初始化")
		while(i<10){
			console.log("哈哈哈")
			yield i;
			console.log("呵呵呵");
			i++;
		}
	}
	
	let fnx = fn();
	console.log(fnx.next());
	console.log(fnx.next());
	
	*/
   
   
	
	function* func(){
		new Promise(function(resolve){
			load("./data/1.json",function(data){
				document.write(data);
				resolve("ok")
			});
		}).then()
	
	 console.log("two");
	 yield '2'; 
	 console.log("three");
	 yield '4';
	 console.log("555");
	 return '5';
	}
	
	let f = func();
	    //r.next()   {value:"返回值",done:false}   done完成状态
	while(!(r=f.next()).done){
		console.log(r.value);
	}
	
	//可以使用promise来解决
	function load(url,result){
		let xhr = new XMLHttpRequest();
		xhr.open("GET",url);
		xhr.send();
		xhr.onreadystatechange=function(){
			if(xhr.readyState == 4 && xhr.status == 200){
				let txt = xhr.responseText;
				result(txt);
			}
		}
	}
	//call是一个回调函数
	function call(xx){
		console.log(xx)
	}
	
	function eat(fun){
		fun("hello");
	}
	
	eat(call);
	
	
</script>
</html>